package com.bo.mybatis.mapper;

import com.bo.mybatis.model.StudentInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentInfoMapper2 {
    // 通过id查询student(获取参数的形式为: #{参数名} )
    @Select("select * from student where id = #{id}")
    StudentInfo selectById(Integer id);
    // 通过chinese和math查询student
    @Select("select * from student where chinese > #{chinese} and math > #{math}")
    List<StudentInfo> selectByChineseAndMath(Integer chinese, Integer math);
    // 只依靠一个数据查询时,即使参数名不匹配也会自动匹配
    @Select("select * from student where english > #{abc}")
    List<StudentInfo> selectByEnglish(Integer english);
    // 依靠多个数据查询时,也可以按照参数顺序查询
    @Select("select * from student where id > #{param1} and math > #{param2}")
    List<StudentInfo> selectByIdAndMath(Integer id,Integer math);
    // @Param注解进行起别名
    @Select("select * from student where id != #{number1} and math > #{number2}")
    List<StudentInfo> getListById(@Param("number1") Integer id,@Param("number2") Integer math);
    // 向数据库插入数据,并且返回影响的行数
    @Insert("insert into student (id,name,chinese,math,english) " +
            "value(#{id},#{name},#{chinese},#{math},#{english})")
    Integer insert(Integer id,String name,Integer chinese,Integer math,Integer english);
    // 通过Id删除数据库的数据,并且返回影响的行数
    @Insert("delete from student where id = #{id}")
    Integer deleteById(Integer id);
    // 修改student的班级号或学校号
    @Update("update student set class_id = #{classId},School_id = #{schoolId} where id = #{id}")
    Integer updateClassAndSchool(Integer classId,Integer schoolId,Integer id);
    // 通过@Options注解获取主键id的值
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into student (name,chinese,math,english) " +
            "value(#{name},#{chinese},#{math},#{english})")
    Integer insertAndGetId(StudentInfo userInfo);
}

